package tortoiseharerace2;

/**
 * Created by pc on 4/10/16.
 */
public class HareThread extends Thread {
        private boolean[] flags = {true, false};
        private int totalStep;
        private int step;

        public HareThread(int totalStep) {
        this.totalStep = totalStep;
    }

        @Override
        public void run() {
        while (step < totalStep) {
            boolean isHareSleep = flags[(int) (Math.random()*10) % 2];
            if (isHareSleep) {
                System.out.println("the hare falls asleep");
            } else {
                step += 2;
                System.out.printf("the hare runs %d steps%n", step);
            }
        }
    }
}
